<?php 
/////////////////////////////////////////////////////////////////////////////////////		
include "required_code.php"; 

				session_start();
				$ses_user_id =$_SESSION['ses_user_id'];
				$ses_std_id = $_SESSION['ses_std_id'];
				if($ses_user_id <> session_id() or  $ses_std_id ==''){
					echo "Authentication failed";
					echo "<meta http-equiv='refresh' content='2;URL=index.php' />";
					}    
					
							$query2="SELECT * FROM std_progress WHERE std_id=$ses_std_id";
							$db_result2=db_query($query2);
							$result2=mysql_fetch_array($db_result2);
							//echo $result2['pretest_sts'];
							if($result2['pretest_sts']!=1){
								echo "Redirecting";
								echo "<meta http-equiv='refresh' content='1;URL=progress.php' />";
							}
							else{
								
		/////////////////////////////////////////////////////////////////////////////////////						
						?>
						
						<table width="800" border="1" align="center" cellpadding="0" cellspacing="0">
						  <tr>
							<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
							  <tr>
								<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
								  <tr>
									<td width="23%" bgcolor="#FFFFFF"><?php include "header.html"; ?></td>
									</tr>
								</table></td>
							  </tr>
							  <tr>
								<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
								  <tr>
								   
									<td width="80%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
									  <tr>
										<td bgcolor="#00CCFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
										  <tr>
											<td><div align="left"><tt><a href="progress.php">Home</a> &gt; Pretest Results</tt></div></td>
											<td>&nbsp;</td>
											<td><?php include "right_navi.php"; ?></td>
										  </tr>
										</table></td>
									  </tr>
									  <tr>
										<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
										  <tr>
											<td bgcolor="#FFFFFF"><br />
											  <table width="100%" border="0" cellspacing="0" cellpadding="5">
												<tr>
												  <td>
                                                  <?php ////////////////////////////PRETEST RESULT///////////////////////////////
			$sum=0;
			for ($i=1;$i<=$test_item;$i++){
					$query2="SELECT * FROM std_ans WHERE std_id='".$ses_std_id."' AND test_item='".$i."'";
					$db_result2=db_query($query2);
					$result2=mysql_fetch_array($db_result2);
					$result2['test_ans'];
					$query3="SELECT * FROM test_items WHERE Item_No='".$i."'";
					$db_result3=db_query($query3);
					$result3=mysql_fetch_array($db_result3);
					$result3['Item_Ans'];

						if($result2['test_ans'] == $result3['Item_Ans'] && $result2['test_ans']!="") {
							$query_insert_test_result="UPDATE std_ans SET test_result='1' WHERE std_id='".$ses_std_id."' AND test_item='".$i."'" ;
							db_query($query_insert_test_result);
							echo "Item ".$i." is CORRECT.<BR>";
							$sum++;
						}
						else{
							$query_insert_test_result="UPDATE std_ans SET test_result='0' WHERE std_id='".$ses_std_id."' AND test_item='".$i."'" ;
							db_query($query_insert_test_result);
							echo "Item ".$i." is WRONG.<BR>";

						}
				 }
				
				echo "<H1>Your Pretest Score is ".$sum." / ".$test_item.".</H1><hr>";

				////////////////////////////PRETEST RESULT///////////////////////////////
				?>
                                                  <a href="progress.php">HOME</a></td>
												</tr>
												<tr>
												  <td></td>
												</tr>
												<tr>
												  <td></td>
												</tr>
											  </table></td>
										  </tr>
										</table></td>
									  </tr>
									</table></td>
								  </tr>
								</table></td>
							  </tr>
							  <tr>
								<td bgcolor="#FFFFFF"><?php include "footer.html"; ?></td>
							  </tr>
							</table></td>
						  </tr>
						</table>
						</body>
						</html>
						<?php
						/////////////////////////////////////////////////////////////////////////////////////		
							$db_close=db_disconnect($db_open);
							}
/////////////////////////////////////////////////////////////////////////////////////		
?>
